﻿//根据XML数据,显示出树型菜单
//作者:刘伟
//日期:2007-11-27
//url,数据的地址,id,显示控件的页面控件ID,pars获取url数据时的参数,options显示相关参数集合
this.oClientDataSet = new Object();
var CreatorTree = function(container,name,options){	 
	this.options = {
	        GetDataPara:"",
		    IconPath:"",
            GetDataUrl:"Channel.xml",
            GetDataPara:"",
            ShowCheckBox:false,
            ShowContextMenu:false,
            ResponseOnclick:true,//响应鼠标左键
            OnNodeSelectToSelectParent:true,//是否允许向上递归
            OnNodeSelectToSelectChildern:true,//是否允许向下递归
            OnNodeSelectToOnlySelectParent:false,//是否选择父节点，只要有一个子节点选中就选中父节点
            FunctionPointType:0,//1会员功能点,2后台功能点,0普通
            FunctionPointSpace:"&nbsp;&nbsp;&nbsp;&nbsp;" ,
            SaveToClient:false ,//是否存到客户端
            isSaveKey:"",//客户端缓存Key
            SingleExpand:false,//是否单一展开
            RightStr:"", //权限字段
            OverBackColor:"#D4D0C8",//移动背景色
            OutBackColor:"",//移出背景色
            SubRootLevel:0,//起始节点的级别差
            SingleSelect:true,//是否始单选
            ExpandLevel:0,//默认展开级别
            IsAsynLoad:true,//是否异步现在暂时未用
            AllowToNavigatorOnHasNode:false,//是否运行有节点的节点点击时，也执行其导航函数 
            DefaultSelectedValue:"" //如果树有checkbox时，默认的付值的选择节点
	}
	Object.extend(this.options,options||{});
	 //当前展开树节点
    this.CurrentTreeid="";    
    this.Name=(name==null || name=="")?"CreatorTree"+(new Date()).getTime():name;//"CreatorTree"+(new Date()).getTime()
    this.Container=$(container);
    this.CurrentNode=null;
    this.CurrrentParentNode=null;
    this.InstinceHTML="";    
    
    this.NodesList   = new ArrayList();
    this.IconPath=this.options.IconPath;
    this.GetDataUrl=this.options.GetDataUrl;
    if(this.GetDataUrl=="")
        this.GetDataUrl="Tree.xml";
    this.GetDataPara=this.options.GetDataPara;
    this.ShowCheckBox=this.options.ShowCheckBox;
    this.ShowContextMenu=this.options.ShowContextMenu;
    //响应鼠标左键
    this.ResponseOnclick=this.options.ResponseOnclick;
    //是否允许向上递归
    this.OnNodeSelectToSelectParent=this.options.OnNodeSelectToSelectParent;
    //是否允许向下递归
    this.OnNodeSelectToSelectChildern=this.options.OnNodeSelectToSelectChildern;
    //是否选择父节点，只要有一个子节点选中就选中父节点
    this.DefaultSelectedValue=new Array();
    this.OnNodeSelectToOnlySelectParent=this.options.OnNodeSelectToOnlySelectParent;
    if(this.options.DefaultSelectedValue!=null && this.options.DefaultSelectedValue!='')
    {
        var arr=this.options.DefaultSelectedValue.split(','); 
        var k=0;
        for(var i=0;i<arr.length;i++)
        {
            if(arr[i]!="")
                this.DefaultSelectedValue[k++]=arr[i];
        }
    }
    //1会员功能点,2后台功能点,0普通
    this.FunctionPointType=this.options.FunctionPointType;
    this.FunctionPointSpace=this.options.FunctionPointSpace;
    //是否存到客户端
    this.SaveToClient=this.options.SaveToClient;
    //客户端缓存Key
    this.isSaveKey=this.options.isSaveKey;
    //是否单一展开
    this.SingleExpand=this.options.SingleExpand;    
    this.RightStr=this.options.RightStr; 
    //移动背景色
    this.OverBackColor=this.options.OverBackColor;
    //移出背景色
    this.OutBackColor=this.options.OutBackColor;
    //起始节点的级别差
    this.SubRootLevel=this.options.SubRootLevel;
    //是否始单选
    this.SingleSelect=this.options.SingleSelect;
    //展开级别
    this.ExpandLevel=this.options.ExpandLevel;
    //是否异步
    this.IsAsynLoad=this.options.IsAsynLoad;
    //是否运行有节点的节点点击时，也执行其导航函数
    this.AllowToNavigatorOnHasNode=this.options.AllowToNavigatorOnHasNode;    
    this.TempDom=null;
    this.Temphtml="";
    this.TempRues="";
    this.RootList= new ArrayList();      
    //错误或者加载消息相关
    this.ErrorUnCreateHttpRequest="错误：不能创建HTTP异步请求，无法获取数据";
    this.LoadDataWaitingMsg= '<img src="'+this.IconPath+'Progress.gif"  border="0"/>';    
    this.ItemRoot=null;
    this.Icons=
    {
        L0        : 'L0.gif',  //┏
		L1        : 'L1.gif',  //┣
		L2        : 'L2.gif',  //┗
		L3        : 'L3.gif',  //━
		L4        : 'L4.gif',  //┃
		L5        : 'L5.gif',  //blank
		P0       : 'P0.gif',  //＋┏
		P1       : 'P1.gif',  //＋┣
		P2       : 'P2.gif',  //＋┗
		P3       : 'P3.gif',  //＋━
		M0       : 'M0.gif',     //－┏
        M1       : 'M1.gif',     //－┣
        M2       : 'M2.gif',     //－┗
        M3       : 'M3.gif',     //－━
        
        OpenRoot    : 'root.gif',
        OpenFolder  : 'expand.gif',
        
        CloseRoot   : 'root.gif',  
        CloseFolder : 'close.gif',
		File        : 'file.gif',
		Folder      : 'folder.gif',
		FolderOpen  : 'folderopen.gif',
		Progress    : 'progress.gif'
    };
//    this.IniTree();
//     //调用生成树的函数
//    this.Drawing();
this.Create();
}

CreatorTree.prototype={
    Node:function() //树型结点
    {
        this.Id="";
        this.ParentId="";
        this.Text="";
        this.TipTitle="";
        this.Url="";
        this.ExpandIcon="";
        this.CloseIcon="";
        this.FunctionPoint="";
        this.SelectFunctionPoint="";
        this.NodeClass="";
        this.NodeLevel=0;
        this.ChildernCount=0;
        this.NodeIsys=0;
        this.IsSelect=false;
        this.isExpand=false;
        this.IsLoad=false;
        this.HasChildren=0;
        this.IsLast=false;
        this.ParentLevelIcon="";        
    },   
    Create:function(){
		$(this.Container).innerHTML =this.LoadDataWaitingMsg;
		var xmlHttpReq;
		if(window.ActiveXObject){
		try{xmlHttpReq = new ActiveXObject('Msxml2.XMLHTTP');}
		catch(e){
				try{xmlHttpReq = new ActiveXObject('Microsoft.XMLHTTP');}
				catch(ex){xmlHttpReq = null;}
			}
		}else if(window.XMLHttpRequest){//for Mozilla, Safari,...
			xmlHttpReq = new XMLHttpRequest();
			if (xmlHttpReq.overrideMimeType) {//for some Mozilla
				xmlHttpReq.overrideMimeType('text/xml');
			}
		}
		if(!xmlHttpReq){
			alert(this.ErrorUnCreateHttpRequest);
			return false;
		}
		xmlHttpReq.onreadystatechange=function(){
			if (xmlHttpReq.readyState==4){
				if(xmlHttpReq.status==200){				    
					this.ItemRoot = xmlHttpReq.responseXML.documentElement;	
					this.Create_Item(this.ItemRoot);
				}else{$(this.Container).innerHTML=xmlHttpReq.status+this.ErrorUnCreateHttpRequest}
			}
		}.bind(this);
		var _url=this.GetDataUrl;
		xmlHttpReq.open('GET',_url,true);
		xmlHttpReq.send(null);
	},     
    
    //根据获取的数据生成树
    Create_Item:function(root){
        try
        {
		    $(this.Container).innerHTML ='<img src="'+this.getIcon('Progress')+'" border="0"/>';
		    var rethtml="";
            this.RootList=this.GetRootNodeList(root);
            var rootcount=this.RootList.getCount();
             for(var i=0;i<rootcount;i++)
             {
                 this.Temphtml="";
                 var rootnode=this.RootList.indexUp(i);
                       
                 rethtml+=this.DrawRoot(rootnode,rootcount,i);
                
                 if(i==(rootcount-1))
                    rootnode.IsLast=true;
                 else
                     rootnode.IsLast=false;
                 var treenodeid=this.Name+"_tree_"+rootnode.Id;
                    if(rootnode.HasChildren)
                    {       
                        
                        this.Temphtml="";
                        if(this.ExpandLevel>rootnode.NodeLevel)
                        {
                            this.Temphtml+="<span id='"+treenodeid+"' style='display: block'>";
                        }
                        else{
                            this.Temphtml+="<span id='"+treenodeid+"' style='display: none'>"; } 
                        this.RecursDrawTreeByPid(rootnode);
                        this.Temphtml+="</span>";
                    }
                    else
                    {
                        this.Temphtml="<span id='"+treenodeid+"' style='display: none'></span>";
                    }                   
                  rethtml+=this.Temphtml; 
                  //alert(this.Temphtml);
                  
              }
              
             $(this.Container).innerHTML=rethtml; 
             //text=rethtml; 
             this.Temphtml="";
            
		}
		catch(e)
		{
		    alert(e.message);
            alert("生成树时发生错误，失败！");
		}
	},
	Jtrim:function(el){el=el.replace(/(^\s+)|\s+$/g,"") ;return el;},   
    CheckNodeIsRoot:function(nodeid)
    {
        var ret=false;
        for(var i=0;i<this.RootList.getCount();i++)
        {
            var node=this.RootList.indexUp(i);
            if(node.Id==nodeid)
            {
                ret=true;
                break;
            }
        }
        return ret;
    },  
    GetDOMAttribute:function(item,key)
    {
        var ret=null;
        try{
          ret=item.getAttribute(key);
          return ret;
        }
        catch(e)
        {
        return null;
        }
    },
    AddSubNodeToDomXMLList:function(retlist,dom,node)
    {
        if(this.GetSubNodeCount(dom)<1 || node==null)
         {
            return retlist;      
         }       
         var icount=0;
         var nodecount=this.GetSubNodeCount(dom);
         for(var i=0;i<dom.childNodes.length;i++)
         {
             var  singlenode=dom.childNodes[i];
             var  _node=new this.Node;
             if(this.GetDOMAttribute(singlenode,"id")!=null)
             {
                _node.Id      = this.GetDOMAttribute(singlenode,"id");// singlenode.getAttribute("id");
                _node.ParentId    =  this.GetDOMAttribute(singlenode,"pid");
                  _node.Text = this.GetDOMAttribute(singlenode,"text");
                _node.Url    =  this.GetDOMAttribute(singlenode,"url");
                _node.TipTitle   =  this.GetDOMAttribute(singlenode,"tiptitle");      
                _node.ChildernCount  =  this.GetSubNodeCount(singlenode);
                if(_node.ChildernCount>0)
                     _node.HasChildren    =  true;
                else
                     _node.HasChildren    =  false;
                _node.FunctionPoint  = this.GetDOMAttribute(singlenode,"functionpoint");
                _node.SelectFunctionPoint=   this.GetDOMAttribute(singlenode,"selectfunctionpoint");
                _node.NodeIsys   =   this.GetDOMAttribute(singlenode,"issys");
                _node.ExpandIcon=(_node.ChildernCount>0)?this.getIcon("FolderOpen"):this.getIcon("File"); 
                _node.CloseIcon=(_node.ChildernCount>0)?this.getIcon("Folder"):this.getIcon("File");
                _node.NodeClass  =   this.GetDOMAttribute(singlenode,"nodeclass");
                _node.NodeLevel  =  this.GetDOMAttribute(singlenode,"nodelevel"); 
               _node.NodeLevel  = node.NodeLevel+1;
                var isselect     =  this.GetDOMAttribute(singlenode,"isselect");
                if(isselect==1)
                    _node.IsSelect  = true;
                else
                     _node.IsSelect  = false;
              
                if(this.ExpandLevel>_node.NodeLevel)
                {
                    _node.isExpand=true;
                   
                }
                else
                {
                    _node.isExpand=false;
                    //_node.IsLoad=false;
                }
                 _node.IsLoad=true;
                if(icount==(nodecount-1))
                    _node.IsLast=true;

                   var childAppendimg="";
                   if(!node.IsLast)
                         childAppendimg=this.getIcon("L4");
                   else
                        childAppendimg=this.getIcon("L5");
                  _node.ParentLevelIcon=node.ParentLevelIcon+"<IMG border='0' align='absmiddle' src='"+childAppendimg+"'>";
                retlist.setAt(_node.Id,_node);
                icount++;
               if(_node.ChildernCount>0)
               {
                    this.AddSubNodeToDomXMLList(retlist,singlenode,_node);
                }
            }
         }         
    },
    GetRootNodeList:function(dom) //并且在这里递归得到所的结点集合
    {      
         var retlist=new ArrayList();
         var xmldomlist= new ArrayList();
         if(this.GetSubNodeCount(dom)<1)
         {
            return retlist;      
         }
         var icount=0;
         var nodecount=this.GetSubNodeCount(dom);
             
         for(var i=0;i<dom.childNodes.length;i++)
         {
             var  singlenode=dom.childNodes[i];
             var  _node=new this.Node;
             if(this.GetDOMAttribute(singlenode,"id")!=null)
             {
                _node.Id      = this.GetDOMAttribute(singlenode,"id");
                _node.ParentId    =  this.GetDOMAttribute(singlenode,"pid");
                  _node.Text = this.GetDOMAttribute(singlenode,"text");
                _node.Url    =  this.GetDOMAttribute(singlenode,"url");
                _node.TipTitle   =  this.GetDOMAttribute(singlenode,"tiptitle");    
                _node.ChildernCount  =  this.GetSubNodeCount(singlenode);
                if(_node.ChildernCount>0)
                     _node.HasChildren    =  true;
                else
                     _node.HasChildren    =  false;
                _node.FunctionPoint  = this.GetDOMAttribute(singlenode,"functionpoint");
                _node.SelectFunctionPoint=   this.GetDOMAttribute(singlenode,"selectfunctionpoint");
                _node.NodeIsys   =   this.GetDOMAttribute(singlenode,"issys");                
                _node.ExpandIcon=(_node.ChildernCount>0)?this.getIcon("FolderOpen"):this.getIcon("File");                
                 _node.CloseIcon=(_node.ChildernCount>0)?this.getIcon("Folder"):this.getIcon("File");
                _node.NodeClass  =   this.GetDOMAttribute(singlenode,"nodeclass"); 
                _node.NodeLevel=this.SubRootLevel;
                var isselect     =  this.GetDOMAttribute(singlenode,"isselect");
                if(isselect==1)
                    _node.IsSelect  = true;
                else
                     _node.IsSelect  = false;
                 if(this.ExpandLevel>_node.NodeLevel)
                {
                    
                    _node.isExpand=true;
                   
                    
                }
                else
                {
                    _node.isExpand=false;
                   
                    //_node.IsLoad=false;
                }        
                _node.IsLoad=true;  
                 if(icount==(nodecount-1))
                    _node.IsLast=true;
                icount++;    
                retlist.setAt(_node.Id,_node);
                xmldomlist.setAt(_node.Id,_node);
                if(_node.ChildernCount>0)
                {                  
                    this.AddSubNodeToDomXMLList(xmldomlist,singlenode,_node);
                }
            }
         }
          this.NodesList= xmldomlist;   
         return retlist;   
    },  
    
    //获取子结点数
    GetSubNodeCount:function(dom)
    {
         if(dom==null ||dom.childNodes==null|| dom.childNodes.length<1)
         return 0;
         var count=0;
         for(var i=0;i<dom.childNodes.length;i++)
         {
            if(this.GetDOMAttribute(dom.childNodes[i],"id")!=null)
             {
                count++;
             }
         }
         return count;
    },
    
    DrawRoot:function(rootnode,rootcount,i)
    {       
        var haschild=rootnode.HasChildren;
        var expandimgName="";
        if(this.ExpandLevel>rootnode.NodeLevel)
        {
            if(rootcount>1)
            {
                if(i==0)
                    expandimgName=haschild ? "M3" :"M3";
                else
                {
                    if(i==(rootcount-1))
                        expandimgName=haschild ? "M2" :"M2";
                    else
                        expandimgName=haschild ? "M1" : "M3";
               }
           }
           else
           {    
                expandimgName=haschild ? "M3" :"M3";
           }
       }
       else
       {
          if(rootcount>1)
            {
                if(i==0)
                    expandimgName=haschild ? "P3" :"L0";
                else
                {
                    if(i==(rootcount-1))
                        expandimgName=haschild ? "P3" :"L2";
                    else
                        expandimgName=haschild ? "P3" : "L1";
               }
           }
           else
           {    
           
                 if(this.ExpandLevel>rootnode.NodeLevel)
                    expandimgName=haschild ? "M3" :"L3";
                  else
                    expandimgName=haschild ? "P3" :"L3";
                 
           }
       }
        expandimgName=this.getIcon(expandimgName);
 
        var expandimgtagid=this.Name+"_expand_"+rootnode.Id;
        var imgicontagid=this.Name+"_icon_"+rootnode.Id;
       
        
        var linkid=this.Name+'_link_'+rootnode.Id;
        var linkurl=rootnode.Url;
        var checkhtml="";
        if(this.ShowCheckBox)
        {
            if(rootnode.Id!=-1)
            {
                var checkid=this.Name+'_check_'+rootnode.ParentId+"_"+rootnode.Id+"_"+rootnode.HasChildren+"_"+rootnode.NodeIsys;
                var checkedstr=rootnode.IsSelect?"checked":"";
                if(this.DefaultSelectedValue!=null && this.DefaultSelectedValue.length>0)
                {
                    for(var i=0;i<this.DefaultSelectedValue.length;i++)
                    {
                        if(rootnode.Id==this.DefaultSelectedValue[i])
                        {
                           checkedstr="checked";
                           break; 
                        }
                    }
                }
                checkhtml+="<input  type=\"checkbox\"  id=\""+checkid+"\" "+checkedstr+" style='visibility: visible; cursor: hand;' onclick=\""+this.Name+".selectCheckbox('"+checkid+"');\">";
            }
        }
         var sedhtml="<div nowrap>";
         sedhtml+="<span onmouseover=\"this.style.backgroundColor='"+this.OverBackColor+"'\" onmouseout=\"this.style.backgroundColor='"+this.OutBackColor+"'\">";
         sedhtml+=rootnode.ParentLevelIcon;
         sedhtml+="<img id='"+expandimgtagid+"' style='curosr: hand' onclick=\""+this.Name+".Expand('"+rootnode.Id+"');\"  src='"+expandimgName+"' align=\"absMiddle\" border=\"0\" />";
         
        if(this.ShowContextMenu)
			sedhtml+="<span oncontextmenu='"+this.Name+".PopContextMenu("+rootnode.Id+","+rootnode.ParentId+")'>";
        else
            sedhtml+= "<span oncontextmenu=''>";
         
         sedhtml+=checkhtml;
         sedhtml+="<img id='"+imgicontagid+"' src='"+rootnode.CloseIcon+"' onclick=\""+this.Name+".Expand('"+rootnode.Id+"')\"; align=\"absMiddle\" border=\"0\" style=\"cursor: hand\" />";    
       
		 if(this.ResponseOnclick)
         {
            if(!rootnode.HasChildren || this.AllowToNavigatorOnHasNode)
            {
			    sedhtml+=" <a class='"+rootnode.NodeClass+"' id='"+linkid+"' title='"+rootnode.TipTitle+"'";
			    sedhtml+=" onclick=\"mynavigationto('"+rootnode.Url+"','"+rootnode.Id+"','"+rootnode.Text+"','"+rootnode.TipTitle+"',"+rootnode.HasChildren+","+rootnode.NodeIsys+","+rootnode.NodeLevel+");\"";
			    sedhtml+=" href='javascript:void(0)'>"+rootnode.Text+"</a>";
			}
			else
			{
			    sedhtml+=" <a class='"+rootnode.NodeClass+"' id='"+linkid+"' title='"+rootnode.TipTitle+"'";
			    sedhtml+="  onclick=\""+this.Name+".Expand('"+rootnode.Id+"');\"";
			    sedhtml+=" href='javascript:void(0)'>"+rootnode.Text+"</a>";
			}
         }
         else
         {
			sedhtml+=" <a class='"+rootnode.NodeClass+"' id='"+linkid+"' title='"+rootnode.TipTitle+"'";
			sedhtml+=" onclick=\"javascript:return;\"";
			sedhtml+=" href='javascript:void(0)'>"+rootnode.Text+"</a>";
         }
        
         if(this.FunctionPointType>0){
         var tempfunctionhtml=this.GetFunctionPointHtml(rootnode);
         sedhtml+= tempfunctionhtml;
         }
         sedhtml+="  </span> ";
         sedhtml+="  </span></div> ";
     
         return sedhtml;
         
    },
    GetNodeListByPidFromList:function(nodeid)
    {
         var retlist=new ArrayList();
         var nodecount=this.NodesList.getCount();
         var _node=null;
         for(var i=0;i<nodecount;i++)
         {
             _node=this.NodesList.indexUp(i); 
             if(_node.ParentId==nodeid)
                 retlist.setAt(_node.Id,_node);
         } 
         return retlist;
    },    
  
    getDOMSelectNodes:function(node,path)
    {
        if(window.ActiveXObject)
            return node.documentElement.selectNodes(path);
        else
            return node.getElementsByTagName(path);
    }, 
    getFunctionPointName:function(optype)
    {
        if( this.RightStr=="")
            return "没有设定权限点的值";
        else
        {
           return this.RightStr[optype];
        }
        
    },
    getMemberFunctionPoint:function(optype)
    {
        
        var retvalue="none";
        switch(optype)
        {
            case "1":
                retvalue="发布";
                break;
            case "2":
                retvalue="浏览";
                break;
            case "3":
                retvalue="品论/回复";
                break;
            case "4":
                retvalue="查看";
                break;
            case "5":
                retvalue="发布终审";
                break;
            case "6":
                retvalue="评论终审";
                break;
        }
        return retvalue;
    },
    getAdminFunctionPoint:function(optype)
    {
        var retvalue="";

        switch(optype)
        {
            case "1":
                retvalue="添加";
                break;
            case "2":
                retvalue="编辑";
                break;
            case "3":
                retvalue="删除";
                break;
            case "4":
                retvalue="审核";
                break;
            case "5":
                retvalue="锁定";
                break;
            case "6":
                retvalue="热点";
                break;
            case "7":
                retvalue="推荐";
                break;
            case "8":
                retvalue="置顶";
                break;
           case "9":
                retvalue="打印";
                break;
           case "10":
                retvalue="查询";
                break; 
           case "11":
                retvalue="查看";
                break;
           case "12":
                retvalue="导出";
                break; 
           case "13":
                retvalue="奖励";
                break;
           case "14":
                retvalue="冲值";
                break;     
           case "15":
                retvalue="生成静态";
                break;
            case "16":
                retvalue="上下架";
                break;
           case "17":
                retvalue="促销";
                break;
          case "18":
                retvalue="客户确认";
                break;
           case "19":
                retvalue="到帐确认";
                break;
            case "20":
                retvalue="物流处理";
                break;
             case "21":
                retvalue="状态处理";
                break;
            case "22":
                retvalue="订单开票";
                break;
            case "23":
                retvalue="订单分配";
                break;
            case "24":
                retvalue="订单发货";
                break;                
        }
        return retvalue;
    },
    GetIsSelect:function(FunctionPoint,SelectFunctionPoint)
    {
        if(SelectFunctionPoint.length<=0)
            return false;
        var boolretvalue=false;
        var selectfparray=SelectFunctionPoint.split(",");
        for(var i=0;i<selectfparray.length;i++)
        {
             if(FunctionPoint.IndexOf(selectfparray[i]))
             {
                boolretvalue=true;
                break;
             }
        }  
        return  boolretvalue;
    },
    GetFunctionPointHtml:function(mtreenode)
    {
        var functionhtml=" ";
        if( mtreenode.FunctionPoint!="")
        {
            functionhtml+="<FONT color=blue>"+ this.FunctionPointSpace+"</FONT>&nbsp;&nbsp;&nbsp;&nbsp;";
            functionhtml+="<SPAN>";
            var checkid="";
            var operatename="";
            var fparray=mtreenode.FunctionPoint.split(",");
            var checkedstr=this.GetIsSelect(mtreenode.FunctionPoint,mtreenode.SelectFunctionPoint);
            for(var i=0;i<fparray.length;i++)
            { 
                if(this.FunctionPointType==1)
                 {
                     var pointvalue=fparray[i];
                     operatename=this.getMemberFunctionPoint(pointvalue);
//                     operatename=this.getFunctionPointName(pointvalue);
                     
                     checkid="opfunction_"+this.Name+'_check_'+mtreenode.ParentId+"_"+mtreenode.Id+"_"+pointvalue;
                     
                     if(i<(fparray.length-1))
                        functionhtml+="<Label>"+operatename+"</Label><INPUT id='"+checkid+"' "+checkedstr+" style='VISIBILITY: visible; cursor:hand; ' onclick=\""+this.Name+".selectFunctionCheckbox('"+checkid+"');\"  type=checkbox >&nbsp;&nbsp;|&nbsp;&nbsp;";
                     else
                        functionhtml+="<Label>"+operatename+"</Label><INPUT id='"+checkid+"' "+checkedstr+" style='VISIBILITY: visible; cursor:hand; ' onclick=\""+this.Name+".selectFunctionCheckbox('"+checkid+"');\"  type=checkbox >";
                 }
                 else if(this.FunctionPointType==2)
                 {
                     var pointvalue=fparray[i];
                     operatename=this.getAdminFunctionPoint(pointvalue);
//                     operatename=this.getFunctionPointName(pointvalue);
                     checkid="opfunction_"+this.Name+'_check_'+mtreenode.ParentId+"_"+mtreenode.Id+"_"+pointvalue;
                     if(i<(fparray.length-1))
                        functionhtml+="<Label>"+operatename+"</Label><INPUT id='"+checkid+"' "+checkedstr+" style='VISIBILITY: visible; cursor:hand; ' onclick=\""+this.Name+".selectFunctionCheckbox('"+checkid+"');\"  type=checkbox >&nbsp;&nbsp;|&nbsp;&nbsp;";
                     else
                        functionhtml+="<Label>"+operatename+"</Label><INPUT id='"+checkid+"' "+checkedstr+" style='VISIBILITY: visible; cursor:hand; ' onclick=\""+this.Name+".selectFunctionCheckbox('"+checkid+"');\"  type=checkbox >";
                 }
            }
          functionhtml+="</SPAN>";  
        }
        return functionhtml;
    },
    
    changeIcon:function(node)
    {
        var treeobj=this.getObjectByid(this.Name+"_tree_"+node.Id);
        var expandimg=this.getObjectByid(this.Name+"_expand_"+node.Id);
        var iconimg=this.getObjectByid(this.Name+"_icon_"+node.Id);
        if(this.CheckNodeIsRoot(node.Id))
        {
            if(node.isExpand)
            {
                treeobj.style.display="none";
                node.isExpand=false;
                iconimg.src=node.CloseIcon;
                if(node.IsLast)
                    expandimg.src=this.getIcon("P3");
                else
                    expandimg.src=this.getIcon("P3");
            }
            else
            {
                treeobj.style.display="block";
                node.isExpand=true;
                iconimg.src=node.ExpandIcon;
                if(node.IsLast)
                    expandimg.src=this.getIcon("M3");
                else
                {
                    expandimg.src=this.getIcon("M3");
                 }   
            }
        }
        else
        {
            if(node.isExpand)
            {
                treeobj.style.display="none";
                node.isExpand=false;
                iconimg.src=node.CloseIcon;
                if(node.IsLast)
                    expandimg.src=this.getIcon("P2");
                else
                    expandimg.src=this.getIcon("P1");
            }
            else
            {
                treeobj.style.display="block";
                node.isExpand=true;
                iconimg.src=node.ExpandIcon;
                if(node.IsLast)
                    expandimg.src=this.getIcon("M2");
                else
                    expandimg.src=this.getIcon("M1");
            }
        }
    },

    getObjectByid:function(objtagid)
    {
        return document.getElementById(objtagid);
    },
    DrawTreeByPid:function(node)
    {
        //var nodelist=this.GetNodeListByPidFromDom(node);
        if(node!=null)
        {
        var nodelist=this.GetNodeListByPidFromList(node.Id);
        var nodecount=nodelist.getCount();
        var _node=null;
        for(var i=0;i<nodecount;i++)
        {
            _node=nodelist.indexUp(i);
            this.Temphtml+= this.DrawTree(_node,_node.IsLast);
        }  
        }  
    },
    DrawTree:function(node,atend)
    {
    
        var _node=node;

        var haschild=_node.HasChildren;//(_node.HasChildren==0)?false:true;

        var expandimgName="";
        if(atend)
            expandimgName=haschild ? "P2" :"L2";
        else
            expandimgName=haschild ? "P1" : "L1";
        expandimgName=this.getIcon(expandimgName);

        var expandimgtagid=this.Name+"_expand_"+_node.Id;

        var imgicontagid=this.Name+"_icon_"+_node.Id;
        var checkhtml="";
        if(this.ShowCheckBox)
        {
            if(_node.Id!=-1)
            {
                var checkid=this.Name+'_check_'+_node.ParentId+"_"+_node.Id+"_"+_node.HasChildren+"_"+_node.NodeIsys;
                var checkedstr=node.IsSelect?"checked":"";
                if(this.DefaultSelectedValue!=null && this.DefaultSelectedValue.length>0)
                {
                    for(var i=0;i<this.DefaultSelectedValue.length;i++)
                    {
                        if(_node.Id==this.DefaultSelectedValue[i])
                        {
                           checkedstr="checked";
                           break; 
                        }
                    }
                }
                checkhtml+="<INPUT id='"+checkid+"' "+checkedstr+" style='VISIBILITY: visible; cursor:hand;' onclick=\""+this.Name+".selectCheckbox('"+checkid+"');\" type=checkbox >";
            }
        }
        var linkid=this.Name+'_link_'+_node.Id;
        var linkurl=_node.Url;
        var treenodeid=this.Name+"_tree_"+_node.Id;
        var sedhtml="";
        sedhtml+="<DIV noWrap>";
        sedhtml+="<SPAN onmouseover=\"this.style.backgroundColor='"+this.OverBackColor+"'\" onmouseout=\"this.style.backgroundColor='"+this.OutBackColor+"'\">";
        sedhtml+=node.ParentLevelIcon;
        sedhtml+="<IMG id='"+expandimgtagid+"' style='curosr: hand' onclick=\""+this.Name+".Expand('"+_node.Id+"');\"  src='"+expandimgName+"' align=\"absMiddle\" border=\"0\">";
        
        if(this.ShowContextMenu)
			sedhtml+="<SPAN oncontextmenu='"+this.Name+".PopContextMenu("+_node.Id+","+_node.ParentId+")'>";
        else
            sedhtml+= "<SPAN oncontextmenu=''>";
        sedhtml+=checkhtml;
        
        sedhtml+="<img id='"+imgicontagid+"' src='"+_node.CloseIcon+"' onclick=\""+this.Name+".Expand('"+_node.Id+"')\"; align=\"absMiddle\" border=\"0\"style='curosr: hand'>";    
		 if(this.ResponseOnclick)
         {
            if(!_node.HasChildren || this.AllowToNavigatorOnHasNode)
            {
			    sedhtml+=" <A class='"+_node.NodeClass+"' id='"+linkid+"' title='"+_node.TipTitle+"'";
			    sedhtml+=" onclick=\"mynavigationto('"+_node.Url+"','"+_node.Id+"','"+_node.Text+"','"+_node.TipTitle+"',"+_node.HasChildren+","+_node.NodeIsys+","+_node.NodeLevel+");"+this.Name+".setCurrentNode('"+_node.Id+"');\"";
			    sedhtml+=" href='#'>"+_node.Text+"</A> ";
			}
			else
			{
			     sedhtml+=" <A class='"+_node.NodeClass+"' id='"+linkid+"' title='"+_node.TipTitle+"'";
			     sedhtml+=" onclick=\""+this.Name+".Expand('"+_node.Id+"');\""+this.Name+".setCurrentNode('"+_node.Id+"');\"";
			    sedhtml+=" href='#'>"+_node.Text+"</A> ";
			}
		 }
		 else
		 {
			sedhtml+=" <A class='"+_node.NodeClass+"' id='"+linkid+"' title='"+_node.TipTitle+"'";
			sedhtml+=" onclick=\"javascript:return;\"";
			sedhtml+=" href='#'>"+_node.Text+"</a> ";
		 }	
		 if(this.FunctionPointType>0){
         var tempfunctionhtml=this.GetFunctionPointHtml(_node);
         
         sedhtml+=tempfunctionhtml;
         }
         
        sedhtml+="  </span> ";
        sedhtml+="  </span></div> ";
        sedhtml+="<span id='"+treenodeid+"' style='display: none'></span>";
        return sedhtml;
    },
 
    RecursDrawTreeByPid:function(node)
    {

        node.IsLoad=true;
        //node.isExpand=true;
        var nodelist=this.GetNodeListByPidFromList(node.Id);
        var nodecount=nodelist.getCount();
        var html="";
        var sspan="";
        var espan="";
        if(nodecount>0)
        {
            var _node=null;
            for(var i=0;i<nodecount;i++)
            {
                 _node=nodelist.indexUp(i);
                 var treenodeid=this.Name+"_tree_"+_node.Id; 
                 html=this.RecursDrawTree(_node,_node.IsLast); 
                 if(_node.HasChildren==true)
                 {
                       if(this.ExpandLevel>_node.NodeLevel)
                      {
                      sspan="<span id='"+treenodeid+"' style='display: block'>";
                      _node.isExpand=true;
                      }
                      else
                      {
                      sspan="<span id='"+treenodeid+"' style='display: none'>";
                      }
                }
                 else
                 {
                    sspan="<span id='"+treenodeid+"' style='display: none'>";
                    }
                 this.Temphtml+=html+sspan;
                 if(_node.HasChildren==true)
                 { 
                      var temp=i;                      
                        this.RecursDrawTreeByPid(_node);
                      i=temp;
                      this.Temphtml+="</span>"; 
                 }
                 else
                 {
                    this.Temphtml+="</span>"; 
                 }                    
                 sspan="";
                 espan="";
            }
        } 
       
    },

    RecursDrawTree:function(node,atend)
    {
         var _node=node;
        var haschild=(_node.HasChildren==0)?false:true;
        var expandimgName="";
        if(this.ExpandLevel>node.NodeLevel)
        {
            if(atend)
                expandimgName=haschild ? "M3" :"L2";  
            else
                expandimgName=haschild ? "M1" : "L1";
        }
        else
        {
            if(atend)
                expandimgName=haschild ? "P2" :"L2";  
            else
                expandimgName=haschild ? "P1" : "L1";
        }    
        expandimgName=this.getIcon(expandimgName);
        var expandimgtagid=this.Name+"_expand_"+_node.Id;

        var imgicontagid=this.Name+"_icon_"+_node.Id;
        var checkhtml="";
        if(this.ShowCheckBox)
        {
            if(node.id!=-1)
            {
                var checkid=this.Name+'_check_'+node.ParentId+"_"+node.Id+"_"+node.HasChildren+"_"+node.NodeIsys;
                var checkedstr=node.IsSelect?"checked":"";
                if(this.DefaultSelectedValue!=null && this.DefaultSelectedValue.length>0)
                {
                    for(var i=0;i<this.DefaultSelectedValue.length;i++)
                    {
                        if(_node.Id==this.DefaultSelectedValue[i])
                        {
                           checkedstr="checked";
                           break; 
                        }
                    }
                }
                checkhtml+="<INPUT id='"+checkid+"' "+checkedstr+" style='VISIBILITY: visible; cursor:hand;' onclick=\""+this.Name+".selectCheckbox('"+checkid+"');\" type=\"checkbox\" />";
            }
        }
        var linkid=this.Name+'_link_'+_node.Id;
        var linkurl=_node.Url;
  
       
        var sedhtml="";
        sedhtml+="<DIV noWrap>";
        sedhtml+="<SPAN onmouseover=\"this.style.backgroundColor='"+this.OverBackColor+"'\" onmouseout=\"this.style.backgroundColor='"+this.OutBackColor+"'\">";
        sedhtml+=node.ParentLevelIcon;
        sedhtml+="<img id='"+expandimgtagid+"' style='curosr: hand' onclick=\""+this.Name+".Expand('"+_node.Id+"');\"  src='"+expandimgName+"' align=\"absMiddle\" border=\"0\" />";
        
        if(this.ShowContextMenu)
			sedhtml+="<span oncontextmenu='"+this.Name+".PopContextMenu("+_node.Id+","+_node.ParentId+")'>";
        else
            sedhtml+= "<span oncontextmenu='' >";
        
        sedhtml+=checkhtml;
        sedhtml+="<img id='"+imgicontagid+"' src='"+_node.CloseIcon+"' onclick=\""+this.Name+".Expand('"+_node.Id+"')\"; align=\"absMiddle\" border=\"0\" style='curosr: hand' />";    
       
		if(this.ResponseOnclick)
        {
          if(!_node.HasChildren || this.AllowToNavigatorOnHasNode)
          {
			    sedhtml+=" <A class='"+_node.NodeClass+"' id='"+linkid+"' title='"+_node.TipTitle+"'";
			    sedhtml+=" onclick=\"mynavigationto('"+_node.Url+"','"+_node.Id+"','"+_node.Text+"','"+_node.TipTitle+"',"+_node.HasChildren+","+_node.NodeIsys+","+_node.NodeLevel+");"+this.Name+".setCurrentNode('"+_node.Id+"');\"";
			    sedhtml+=" href='#'>"+_node.Text+"</A> ";
		  }
		  else
		  {
		       sedhtml+=" <A class='"+_node.NodeClass+"' id='"+linkid+"' title='"+_node.TipTitle+"'";
			    sedhtml+=" onclick=\""+this.Name+".Expand('"+_node.Id+"')\";"+this.Name+".setCurrentNode('"+_node.Id+"');\"";
			    sedhtml+=" href='#'>"+_node.Text+"</A> ";
		  }
        }
        else
        {
			sedhtml+=" <A class='"+_node.NodeClass+"' id='"+linkid+"' title='"+_node.TipTitle+"'";
			sedhtml+=" onclick=\"javascript:return;\"";
			sedhtml+=" href='#'>"+_node.Text+"</A> ";
        }
        var tempfunctionhtml=this.GetFunctionPointHtml(_node);
         sedhtml+= tempfunctionhtml;
        sedhtml+="  </span> ";
        sedhtml+="  </span></div> ";
        return sedhtml;
    } ,
    Collapse:function(nodeid)
    {
        if(!this.SingleExpand)
           return ;
        if(this.CheckNodeIsRoot(nodeid))
            return ;
        var node=null;
        node=this.NodesList.lookUp(nodeid);
        if(node.HasChildren==0)
            return ;
        if(node.IsLoad)
           this.changeIcon(node);
    },
    
    Expand:function(nodeid)
    {
        if(this.CurrentTreeid!="")
        {
            this.Collapse(this.CurrentTreeid);
            this.CurrentTreeid=nodeid;
        }
        else
        {
            this.CurrentTreeid=nodeid;
        }
       
        var node=null;
        node=this.NodesList.lookUp(nodeid);
        if(node.HasChildren==0)
            return ;
        this.Temphtml="";
      
        if(node.IsLoad)
        {
           this.changeIcon(node);
        }
        else
        {
           
            var treeobj=this.getObjectByid(this.Name+"_tree_"+node.Id)
            this.DrawTreeByPid(node);
            treeobj.innerHTML+= this.Temphtml;
            node.isExpand=false;
            node.IsLoad=true;
            this.changeIcon(node);
            this.NodesList.setAt(node.Id,node);
        }
       if(this.ShowCheckBox)
       {
            var _checkid=this.Name+'_check_'+node.ParentId+'_'+node.Id+'_'+node.HasChildren+'_'+node.NodeIsys;
            var tempchk=this.getObjectByid(_checkid);
            if(tempchk.checked)
               this.selectCheckbox(_checkid);
        }
    },

    changeIcon:function(node)
    {
        var treeobj=this.getObjectByid(this.Name+"_tree_"+node.Id);
        var expandimg=this.getObjectByid(this.Name+"_expand_"+node.Id);
        var iconimg=this.getObjectByid(this.Name+"_icon_"+node.Id); 
        if(this.CheckNodeIsRoot(node.Id))
        { 
            if(node.isExpand)
            {
                treeobj.style.display="none";
                node.isExpand=false;
                iconimg.src=node.CloseIcon;
                if(node.IsLast)
                    expandimg.src=this.getIcon("P3");
                else
                    expandimg.src=this.getIcon("P3");
            }
            else
            {
                treeobj.style.display="block";
                node.isExpand=true;
                iconimg.src=node.ExpandIcon;
                if(node.IsLast)
                    expandimg.src=this.getIcon("M3");
                else
                {
                    expandimg.src=this.getIcon("M3");
                 }   
            }
        }
        else
        {  
            if(node.isExpand)
            {               
                treeobj.style.display="none";
                node.isExpand=false;
                iconimg.src=node.CloseIcon;
                if(node.IsLast)
                    expandimg.src=this.getIcon("P2");
                else
                    expandimg.src=this.getIcon("P1");
            }
            else
            {
                treeobj.style.display="block";
                node.isExpand=true;
                iconimg.src=node.ExpandIcon;
                if(node.IsLast)
                    expandimg.src=this.getIcon("M2");
                else
                    expandimg.src=this.getIcon("M1");
            }
        }
    },

    getObjectByid:function(objtagid)
    {
        return document.getElementById(objtagid);
    },

    setCurrentNode:function(nodeid)
    {
      //  this.CurrentNode=this.NodesList.lookUp(nodeid);
      //  this.CurrrentParentNode=this.NodesList.lookUp(this.CurrentNode.ParentId);
    },
    CheckSelfNodeFP:function(node,selfisselect)
    {
        var fparray=node.FunctionPoint.split(",");
        var checkid="";
        for(var i=0;i<fparray.length;i++)
        {      
            var pointvalue=fparray[i];
            checkid="opfunction_"+this.Name+'_check_'+node.ParentId+"_"+node.Id+"_"+pointvalue;
             _checkobj=this.getObjectByid(checkid);
             if(selfisselect)
                _checkobj.checked=true;
             else
                _checkobj.checked=false;
        }  
    },
    CheckParentNodeFP:function(node,pointvalue)
    {
     
        var nodepid=node.ParentId;
        var nodeid=node.Id;

         var _checkid="opfunction_"+this.Name+'_check_'+node.ParentId+"_"+node.Id+"_"+pointvalue;     
          
         _checkobj=this.getObjectByid(_checkid);
         if(_checkobj==null || _checkobj=="")
            return ;
         
          var checkisselect=_checkobj.checked;
        
          var nodelist=this.GetNodeListByPidFromList(nodepid);
          
          var nodecount=nodelist.getCount();
         
          var isallselect=true;
          
          var selectcount=0;
         
         for(i=0;i<nodecount;i++)
         {
            var _node=nodelist.indexUp(i);
           _checkid="opfunction_"+this.Name+'_check_'+_node.ParentId+'_'+_node.Id+'_'+pointvalue;
           _checkobj=this.getObjectByid(_checkid);
           if(_checkobj==null || _checkobj=="")
                continue;
           if(_checkobj.checked)
               selectcount++;
           else
               isallselect=false;
                
        }

        var _pnode=this.NodesList.lookUp(nodepid);
        
        _checkid="opfunction_"+this.Name+'_check_'+_pnode.ParentId+'_'+_pnode.Id+'_'+pointvalue;
        
        _checkobj=this.getObjectByid(_checkid);
        
        if(_checkobj!=null && _checkobj!="")
        {
            if(isallselect)
                _checkobj.checked=true;
            else
                 _checkobj.checked=false;
         }
        if(_pnode.NodeLevel!=0)
        {
            var isroot=this.CheckNodeIsRoot(_pnode.Id);
            if(!isroot)
            {
               this.CheckParentNodeFP(_pnode,pointvalue);
            }
        }
         
    },
    CheckChildrenNodeFP:function(node,pointvalue,ischecked)
    {
         var nodelist=this.GetNodeListByPidFromList(node.Id);
        var nodecount=nodelist.getCount();
        for(var i=0;i<nodecount;i++)
        {
            var _node=nodelist.indexUp(i);
            var _checkid="opfunction_"+this.Name+'_check_'+_node.ParentId+'_'+_node.Id+'_'+pointvalue;
            var _checkobj=this.getObjectByid(_checkid);
             if(_checkobj==null)
                continue;
            _checkobj.checked=ischecked;
            if(_node.HasChildren==1)
            {   
                var temp=i;
                this.CheckChildrenNodeFP(_node,pointvalue,ischecked);
                i=temp;
            }   
        }
    },
    
    selectFunctionCheckbox:function(checkid)
    {
       
        var pointvalue=checkid.split("_")[5];
        var nodepid=checkid.split("_")[3]; 
        var nodeid=checkid.split("_")[4];
      
        var _checkobj=this.getObjectByid(checkid);
        if(_checkobj.checked)
            _checkobj.checked=true;
        else
            _checkobj.checked=false;
            
         var _node=this.NodesList.lookUp(nodeid);  
         var isroot=this.CheckNodeIsRoot(nodeid);
         if(!isroot)
         {
            if(this.OnNodeSelectToSelectParent)
            {
                this.CheckParentNodeFP(_node,pointvalue);
            }
         }
         if(this.OnNodeSelectToSelectChildern)
         {
            this.CheckChildrenNodeFP(_node,pointvalue,_checkobj.checked); 
         }
    },
    selectCheckbox:function(checkid)
    {
        if(this.SingleSelect)
        {
            var nodecount=this.NodesList.getCount();
            var node=null;
            var rootcheckobj=null;
            
            _checkobj=this.getObjectByid(checkid);
            
            var mychecked=_checkobj.checked;
            for(var i=0;i<nodecount;i++)
            {
                node=this.NodesList.indexUp(i);
                var _checkid=this.Name+'_check_'+node.ParentId+'_'+node.Id+'_'+node.HasChildren+'_'+node.NodeIsys;
                _checkobj=this.getObjectByid(_checkid);
                _checkobj.checked=false;
            }
             _checkobj=this.getObjectByid(checkid);
             if(mychecked)
                _checkobj.checked=true;
             else
                _checkobj.checked=false;
    
             var nodeid=checkid.split("_")[3]; 
             this.setCurrentNode(nodeid);
             return ;
        }
        
        var nodepid=checkid.split("_")[2];
        var nodeid=checkid.split("_")[3]; 
        if(this.OnNodeSelectToSelectParent)
        {
            this.recursSelectParent(nodepid,nodeid);
        }
        if(this.OnNodeSelectToSelectChildern)
        {
            var _node=this.NodesList.lookUp(nodeid);
            this.recursSelectChildren(_node);
        }
        

    },

    recursSelectParent:function(currnodepid,nodeid)
    {
        var nodepid=currnodepid;
        var isroot=this.CheckNodeIsRoot(nodeid);
        if(isroot)
            return ;
        var nodelist=this.GetNodeListByPidFromList(nodepid);
        var nodecount=nodelist.getCount();
        var isallselect=true;
        var _node=null;
        var selectcount=0;
        for(var i=0;i<nodecount;i++)
        {
            _node=nodelist.indexUp(i);
            var _checkid=this.Name+'_check_'+_node.ParentId+'_'+_node.Id+'_'+_node.HasChildren+'_'+_node.NodeIsys;
            checkobj=this.getObjectByid(_checkid);
            if(checkobj.checked)
                selectcount++;
            else
                isallselect=false;
        }
        var _pnode=this.NodesList.lookUp(nodepid);
        var _checkid=this.Name+'_check_'+_pnode.ParentId+'_'+_pnode.Id+'_'+_pnode.HasChildren+'_'+_pnode.NodeIsys;
        var checkobj=this.getObjectByid(_checkid);
        if(isallselect)
            checkobj.checked=true;
        else
        {
            if(this.OnNodeSelectToOnlySelectParent)
            {
                if(selectcount==0)
                    checkobj.checked=false;
                else
                    checkobj.checked=true;
            }
            else
                 checkobj.checked=false;
           
        }
        if(_pnode.NodeLevel!=0)
        {
            this.recursSelectParent(_pnode.ParentId,_pnode.Id);
        }
    },

     recursSelectChildren:function(node)
    {
        var nodelist=this.GetNodeListByPidFromList(node.Id);
        var nodecount=nodelist.getCount();
        var _node=null;
        var checked=this.Name+'_check_'+node.ParentId+'_'+node.Id+'_'+node.HasChildren+'_'+node.NodeIsys;
        var checkobj=this.getObjectByid(checked);
        for(var i=0;i<nodecount;i++)
        {
            _node=nodelist.indexUp(i);
            var _checkid=this.Name+'_check_'+_node.ParentId+'_'+_node.Id+'_'+_node.HasChildren+'_'+_node.NodeIsys;
            var _checkobj=this.getObjectByid(_checkid);
            if(checkobj.checked)
                _checkobj.checked=true;
            else
                _checkobj.checked=false;
            
            if(_node.HasChildren==1)
            {   
                
                    var temp=i;
                    this.recursSelectChildren(_node);
                    i=temp;
                
            }   
        }
    },
    SetFunctionSelectCheck:function(checkStr)
    {
        if(this.FunctionPointType==0)        
            return ;
        var arr=checkStr.split("|");
        for(var i=0;i<arr.length;i++)
        {
            var nodeid=arr[i].split("@")[0]; 
            var funpointvalue= arr[i].split("@")[1];
            var funarray=funpointvalue.split(",");
            var node=this.NodesList.lookUp(nodeid);
         
            for(j=0;j<funarray.length;j++)
            {
                  var _checkid="opfunction_"+this.Name+'_check_'+node.ParentId+'_'+node.Id+'_'+funarray[j];
                  var _checkobj=this.getObjectByid(_checkid);
                  if(_checkobj!=null && _checkobj!="")
                        _checkobj.checked=true;
            }
        }
        
    },
    SetSelectCheck:function(nodeid)
    {
        if(!this.ShowCheckBox)
            return ;
        var nodecount=this.NodesList.getCount();
        var arr=nodeid.split(",");
        var includeroot=0;
        for(var i=0;i<arr.length;i++)
        {
            if(arr[i]==this.RootId)
            {
                includeroot=1;
                break;
            }
        }
        if(includeroot==1 && !this.OnNodeSelectToSelectParent)
        {
            if(this.SingleSelect)
            {
                 var node=this.NodesList.lookUp(this.RootId);
                 var _checkid=this.Name+'_check_'+node.ParentId+'_'+node.Id+'_'+node.HasChildren+'_'+node.NodeIsys;
                 _checkobj=this.getObjectByid(_checkid);
                 _checkobj.checked=true;
            }
            else
            {
                for(var i=0;i<nodecount;i++)
                {
                    var node=this.NodesList.indexUp(i);
                    var _checkid=this.Name+'_check_'+node.ParentId+'_'+node.Id+'_'+node.HasChildren+'_'+node.NodeIsys;
                    _checkobj=this.getObjectByid(_checkid);
                    _checkobj.checked=true;
                }
            }
        }
        else
        {
            for(var i=0;i<arr.length;i++)
            {
                for(var j=0;j<nodecount;j++)
                {
                    var node=this.NodesList.indexUp(j);
                    if(node.Id==arr[i])
                    {
                        var _checkid=this.Name+'_check_'+node.ParentId+'_'+node.Id+'_'+node.HasChildren+'_'+node.NodeIsys;
                        _checkobj=this.getObjectByid(_checkid);
                        _checkobj.checked=true;
                    }
                }
            }
        }
    },

    

    GetSelectNode:function()
    {
        var listcount=this.NodesList.getCount();
        var retlist=new ArrayList();
        for(var i=0;i<listcount;i++)
        {
            _node=this.NodesList.indexUp(i);
            var _checkid=this.Name+'_check_'+_node.ParentId+'_'+_node.Id+'_'+_node.HasChildren+'_'+_node.NodeIsys;
            var _checkobj=this.getObjectByid(_checkid);
            if(_checkobj!=null && _checkobj!="undefined")
            {
                if(_checkobj.checked)
                    retlist.setAt(_node.Id,_node); 
            }
        }
        return retlist;
    },
    GetSelectAllNode:function()
    {
        var listcount=this.NodesList.getCount();
        var retlist=new ArrayList();
        for(var i=0;i<listcount;i++)
        {
            _node=this.NodesList.indexUp(i);
            var _checkid=this.Name+'_check_'+_node.ParentId+'_'+_node.Id+'_'+_node.HasChildren+'_'+_node.NodeIsys;
            var _checkobj=this.getObjectByid(_checkid);
            if(_checkobj!=null && _checkobj!="undefined")
            {
                retlist.setAt(_node.Id,_node); 
            }
        }
        return retlist;
    },
    
    GetSelectNodeTextStr:function()
    {
        var list=this.GetSelectNode();
        var retidstr="";
        for(var i=0;i<list.getCount();i++)
        {
            _node=list.indexUp(i);
            retidstr+=_node.Text+",";
        }
        if(retidstr!="")
            retidstr=retidstr.substr(0,retidstr.length-1);
        return retidstr;
    },
    
    GetFunctionPointStr:function()
    {
      
        var retlaststr="";
        var funstr;
        if(this.FunctionPointType>0)
        {
            var listcount=this.NodesList.getCount();
            var retlist=new ArrayList();
            var checkid="";
            var _checkobj=null;
            var  _node=null;
            for(var i=0;i<listcount;i++)
            {
                _node=this.NodesList.indexUp(i);
                var fparray=_node.FunctionPoint.split(",");
                var funstr="";
                for(var j=0;j<fparray.length;j++)
                {      
                    var pointvalue=fparray[j];
                    checkid="opfunction_"+this.Name+'_check_'+_node.ParentId+"_"+_node.Id+"_"+pointvalue;
                    _checkobj=this.getObjectByid(checkid);
                    if(_checkobj!=null)
                    {
                        if(_checkobj.checked)
                            funstr+=pointvalue+",";
                    }
                } 
                if( funstr!="")
                {
                    funstr=funstr.substr(0,funstr.length-1);
                    retlaststr+=_node.Id+"@"+funstr+"|";
                }
                
            }
            if(retlaststr!="")
                retlaststr=retlaststr.substr(0,retlaststr.length-1); 
        }
        return retlaststr;
    },
    
    GetSelectNodeIdStr:function()
    {
        var list=this.GetSelectNode();
        var retidstr="";
        for(var i=0;i<list.getCount();i++)
        {
            _node=list.indexUp(i);
            retidstr+=_node.Id+",";
        }
        if(retidstr!="")
            retidstr=retidstr.substr(0,retidstr.length-1);
        return retidstr;
    },
    GetSelectAllNodeIdStr:function()
    {
        var list=this.GetSelectAllNode();
        var retidstr="";
        for(var i=0;i<list.getCount();i++)
        {
            _node=list.indexUp(i);
            retidstr+=_node.Id+",";
        }
        if(retidstr!="")
            retidstr=retidstr.substr(0,retidstr.length-1);
        return retidstr;
    },
    SetNodeSelect:function(idstr)
    {
        var idlist=idstr.split(",");
        var listcount=this.NodesList.getCount();
        for(var i=0;i<listcount;i++)
        {
            _node=this.NodesList.indexUp(i);
            for(var j=0;j<idlist.length;j++)
            {
                 if(_node.Id==idlist[j])
                 {
                     var _checkid=this.Name+'_check_'+_node.ParentId+'_'+_node.Id+'_'+_node.HasChildren+'_'+_node.NodeIsys;
                     var _checkobj=this.getObjectByid(_checkid);
                     _checkobj.checked=true;
                      break;
                 }
            }
        }
    },
    getIcon:function(IconName)
    {
        return this.IconPath+this.Icons[IconName];
    },
    ReplaceUrlParaValue:function(Paradata,ParaValue)
    {
        var returl="";
        if(Paradata=="")
            returl="para=pnodeid:0";
        else
        {
            if(Paradata.indexOf("pnodeid")<0)
            {
                 returl="para=pnodeid:0";
            }
            else
            {   
                var paraarr=Paradata.split("@");
                for(var i=0;i<paraarr.length;i++)
                {
                    var temparr=paraarr[i].split(":");
                    if(temparr[0]=="pnodeid")
                        returl+="pnodeid:"+ParaValue+"@";
                    else
                        returl+=temparr[0]+":"+temparr[1]+"@";
                }
                var lastindex=returl.length-1;
                var lastchar=returl.substr(lastindex,lastindex-1);
                if(lastchar=="@")
                    returl=returl.substr(0,lastindex);
               returl="para="+returl;
            }
        }
        return returl;
    },
    PopContextMenu:function(mynodeid,mypnodeid)
    {
		 var showoPopup = window.createPopup();
		 
//		 var lefter2 = event.clientY+0;
//		 var topper2 = event.clientX;

         var lefter2=event.clientX;
         var topper2=event.clientY;
            
        
		 var overcolor='#FFEECC';
		 var outcolor='';
		 var html='<table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="1"'+
					' id="file_menu" style="background-color:#8DA2C8;">'+
					'<tr style="height:2px">'+
					'<td>'+
					'<hr style="width:98%;align:left;height:2px;"/></td>'+
					'</tr>'+
					'<tr height="20px">'+
					'<td>'+
					'<a href="#" onMouseOver="this.style.backgroundColor=\''+overcolor+'\'" onMouseOut="this.style.backgroundColor=\''+outcolor+'\'"   style="COLOR: green;FONT-SIZE: 12px; FONT-FAMILY: 宋体, Serif, Arial;" onclick="parent.UmeTreeOpearator('+mynodeid+','+mypnodeid+',\'add\');">Add Node</a></td>'+
					'</tr >'+
					'<tr height="20px">'+
					'<td >'+
					'<a href="#" onMouseOver="this.style.backgroundColor=\''+overcolor+'\'" onMouseOut="this.style.backgroundColor=\''+outcolor+'\'"  style="COLOR: green;FONT-SIZE: 12px; FONT-FAMILY: 宋体, Serif, Arial;" onclick="parent.UmeTreeOpearator('+mynodeid+','+mypnodeid+',\'edit\');" >Modify Node</a></td>'+
					'</tr>'+
					'<tr height="20px">'+
					'<td>'+
					'<a href="#" onMouseOver="this.style.backgroundColor=\''+overcolor+'\'" onMouseOut="this.style.backgroundColor=\''+outcolor+'\'"  style="COLOR: green;FONT-SIZE: 12px; FONT-FAMILY: 宋体, Serif, Arial;" onclick="parent.UmeTreeOpearator('+mynodeid+','+mypnodeid+',\'delete\');" >Delete Node</a></td>'+
					'</tr>'+
					'</table>';
		showoPopup.document.body.innerHTML = html; 
		showoPopup.show(lefter2, topper2, 90, 90,this.TreeDiv);
		event.returnValue=false;
    }
}



var  XmlDom=function(){
    //通过对象/属性检测法，判断是IE来是Mozilla
    if (window.ActiveXObject) {
        var arrSignatures = ["MSXML2.DOMDocument.5.0", "MSXML2.DOMDocument.4.0",
                             "MSXML2.DOMDocument.3.0", "MSXML2.DOMDocument",
                             "Microsoft.XmlDom"];                         
        for (var i=0; i < arrSignatures.length; i++) {
            try {        
                var oXmlDom = new ActiveXObject(arrSignatures[i]);
                return oXmlDom;        
            } catch (oError) {
                //ignore
            }
        } 
        throw new Error("MSXML is not installed on your system.");            
    //同上          
    } else if (document.implementation && document.implementation.createDocument) {        
        var oXmlDom = document.implementation.createDocument("","",null);
//        //创建Mozilla版本的parseError对象
//        oXmlDom.parseError = {
//            valueOf: function () { return this.errorCode; },
//            toString: function () { return this.errorCode.toString() }
//        };        
//        //初始化parseError对象
//        oXmlDom.__initError__();
//        oXmlDom.addEventListener("load", function () {
//            this.__checkForErrors__();
//            this.__changeReadyState__(4);
//        }, false);
        return oXmlDom;
    } else {
        throw new Error("Your browser doesn't support an XML DOM object.");
    }
}

 
var XmlDomLoad=function(obj,_domdoc)
{
    if (window.ActiveXObject)
    {
        obj.loadXML(_domdoc);
    }
    else
    {
        obj.load(_domdoc);
    }
    return obj;
} 
var HttpRequest=function()
{
    var xmlHttpReq;
        if(window.ActiveXObject){
            try{xmlHttpReq = new ActiveXObject('Msxml2.XMLHTTP');}
	        catch(e){
				    try{xmlHttpReq = new ActiveXObject('Microsoft.XMLHTTP');}
				    catch(ex){xmlHttpReq = null;}
			    }
		}else if(window.XMLHttpRequest){//for Mozilla, Safari,...
			xmlHttpReq = new XMLHttpRequest();
			if (xmlHttpReq.overrideMimeType) {//for some Mozilla
				xmlHttpReq.overrideMimeType('text/xml');
			}
		}
		if(!xmlHttpReq){
			alert('Giving up :( Cannot create an XMLHTTP instance');
			return false;
		}
	return xmlHttpReq;
}

var ArrayList=function()
 {
      this.map = new Array();
    //list对象的item
      this.Item=function(key, value)
      {
        this.key = key;
        this.value = value;
      };
      this.setAt=function(key, value)
      {
          for (var i = 0; i < this.map.length; i++)
          {
            if ( this.map[i].key == key )
            {
              this.map[i].value = value;
              return;
            }
          }
          this.map[this.map.length] = new this.Item(key, value);
      };
     this.indexUp=function(index)
     {
         return this.map[index].value;
     };
     this.lookUp=function(key)
     {
          for (var i = 0; i < this.map.length; i++)
          {
            if ( this.map[i].key == key )
            {
              return this.map[i].value;
            }
          } 
          return null;
      };
     this.removeKey=function(key)
     {
          var v;
          for (var i = 0; i < this.map.length; i++)
          {
            v = this.map.pop();
            if ( v.key == key )
              continue;
              
            this.map.unshift(v);
          }
      };

    this.getCount=function()
    {
      return this.map.length;
    };

    this.isEmpty=function()
    {
      return this.map.length <= 0;
    };
}

//// check for XPath implementation
//if( document.implementation.hasFeature("XPath", "3.0") )
//{
//   // prototying the XMLDocument
//   XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
//   {
//      if( !xNode ) { xNode = this; } 
//      var oNSResolver = this.createNSResolver(this.documentElement)
//      var aItems = this.evaluate(cXPathString, xNode, oNSResolver, 
//                   XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
//      var aResult = [];
//      for( var i = 0; i < aItems.snapshotLength; i++)
//      {
//         aResult[i] =  aItems.snapshotItem(i);
//      }
//      return aResult;
//   }

//   // prototying the Element
//   Element.prototype.selectNodes = function(cXPathString)
//   {
//      if(this.ownerDocument.selectNodes)
//      {
//         return this.ownerDocument.selectNodes(cXPathString, this);
//      }
//      else{throw "For XML Elements Only";}
//   }
//}
//// check for XPath implementation
//if( document.implementation.hasFeature("XPath", "3.0") )
//{
//   // prototying the XMLDocument
//   XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
//   {
//      if( !xNode ) { xNode = this; } 
//      var xItems = this.selectNodes(cXPathString, xNode);
//      if( xItems.length > 0 )
//      {
//         return xItems[0];
//      }
//      else
//      {
//         return null;
//      }
//   }
//   
//   // prototying the Element
//   Element.prototype.selectSingleNode = function(cXPathString)
//   {    
//      if(this.ownerDocument.selectSingleNode)
//      {
//         return this.ownerDocument.selectSingleNode(cXPathString, this);
//      }
//      else{throw "For XML Elements Only";}
//   }
//}



var dwn_create_tag = function(tag){return document.createElement(tag);}
var dwnUserAgent = navigator.userAgent;
var dwnIsOpera = dwnUserAgent.indexOf('Opera')>-1;
var dwnIsIE = dwnUserAgent.indexOf('MSIE')>-1 && !dwnIsOpera;
